/**
 * Project Name:template-web
 * File Name   :BaseFilterControl.java
 * Package Name:org.cn.template.component.web.control
 * Date:2015年9月27日下午4:42:04
 * Copyright (c) 2015, http://my.oschina.net/httpssl All Rights Reserved.
 *
*/

package org.cn.template.component.web.control;

import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.http.HttpServletRequest;

/**
 * ClassName:BaseFilterControl <br/>
 * Function :TODO ADD FUNCTION. <br/>
 * Reason	:TODO ADD REASON. <br/>
 * Date     :2015年9月27日 下午4:42:04 <br/>
 * @author  :http://my.oschina.net/httpssl
 * @email   :491835898@QQ.COM
 * @since   :JDK 1.7
 * @see 	 
 * 实现类似美团区域条件过滤
 */
public abstract class BaseFilterControl
{
	private ConcurrentHashMap<String, String>	filterMap							= new ConcurrentHashMap<String, String>();
	protected final String						filter_key_prefix					= "filter_";
	protected final String[]					filter_keys							= { "city", "jy", "xl", "stage", "hy" };
	String										query_filter_url_suffix;
	String										page_query_filter_url_suffix_key	= "query_filter_url_suffix";

	protected void initQueryFilter(HttpServletRequest request)
	{
		StringBuffer key_buffer = new StringBuffer();
		for (String key : filter_keys) {
			String filter_key = key_buffer.append(filter_key_prefix).append(key).toString();
			String filter_key_value = request.getParameter(filter_key);
			if (filter_key_value != null) {
				filterMap.put(filter_key, filter_key_value);
			}
			request.setAttribute(filter_key, filter_key_value);
			key_buffer.setLength(0);
		}
		for (Entry<String, String> filter : filterMap.entrySet()) {
			key_buffer.append(filter.getKey()).append("&").append(filter.getValue());
		}
		query_filter_url_suffix = key_buffer.toString();
		request.setAttribute(page_query_filter_url_suffix_key, query_filter_url_suffix);
	}

	public abstract String get_filter_key_prefix();

	public abstract String[] get_filter_keys();
}
